package com.essence.common.model.parser;

import com.essence.common.model.Packet;
import io.netty.buffer.ByteBuf;

public class MMeNbParser extends ByteBufParser {
    @Override
    void parse(Packet packet, ByteBuf buf) {
        if (packet.getVsq().getSq() == 0) {
            for (int i = 0; i < packet.getVsq().getNum(); i++) {
                int infoAdr = buf.readUnsignedMediumLE();
                int nva = buf.readShortLE();
                short qds = buf.readUnsignedByte();
                Packet.AnalogSignals analogSignals = new Packet.AnalogSignals(infoAdr, nva, null, qds);
                packet.addAnalogSignals(analogSignals);
            }
        }
        if (packet.getVsq().getSq() == 1) {
            int infoAdr = buf.readUnsignedMediumLE();
            for (int i = 0; i < packet.getVsq().getNum(); i++) {
                int nva = buf.readShortLE();
                short qds = buf.readUnsignedByte();
                Packet.AnalogSignals analogSignals = new Packet.AnalogSignals(infoAdr + i, nva, null, qds);
                packet.addAnalogSignals(analogSignals);
            }
        }
    }

    @Override
    int infoObjectLength() {
        return 6;
    }
}
